package com.base.system.base.db.specifications;

import javax.persistence.criteria.*;
import java.util.List;

public class NotInSpecification<T> extends AbstractSpecification<T> {

    private static final long serialVersionUID = 9091723349083848143L;
    private final String property;
    private final List<Object> values;

    public NotInSpecification(String property, List<Object> values, JoinType joinType) {
        this.property = property;
        this.values = values;
        this.joinType = joinType;
    }

    @Override
    public Predicate toPredicate(Root<T> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
        From from = getFrom(property, root);
        String attr = getProperty(property);
        return from.get(attr).in(values).not();
    }

}
